import React from 'react'
import { useState } from 'react'
import { useEffect } from 'react'
import { getBannerList } from './../../api/banner'
import { getProList } from './../../api/pro'
function Home() {
  const [proList, setProList] = useState([])
  const [bannerList, setBannerList] = useState([])
  useEffect(() => {
    // getBannerList().then(res => {
    //   setBannerList(res.data.data)
    // })
    // getProList().then(res => {
    //   setProList(res.data.data)
    // })
    // 核心 Promise.all([promise1, promise2])
    Promise.all([getBannerList(), getProList()]).then(res => {
      console.log(res)
      setBannerList(res[0].data.data)
      setProList(res[1].data.data)
    })

    // axios.all()
    /**
     * function getUserAccount() {
        return axios.get('/user/12345');
      }

      function getUserPermissions() {
        return axios.get('/user/12345/permissions');
      }

      axios.all([getUserAccount(), getUserPermissions()])
        .then(axios.spread(function (acct, perms) {
          // 两个请求现在都执行完成
        }));
     */
  }, [])
  return (
    <div>
      系统首页
      <ul>
        {
          proList && proList.map(item => {
            return <li key = { item.proid }>{ item.proname }</li>
          })
        }
      </ul>
    </div>
  )
}

export default Home
